package com.wei.web.demo.user.config;


import com.wei.web.demo.user.controller.WebSocketController;
import com.wei.web.demo.user.interceptor.HandShakeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    //注册通信接口
    @Autowired
    private WebSocketController webSocketController;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//注册socket地址，以及允许所有请求  以及拦截器验证权限
        registry.addHandler(webSocketController, "/websocket")
                .addInterceptors(new HandShakeInterceptor()).setAllowedOrigins("*");
    }
}
